
package com.dfbz.homework6;
import java.lang.reflect.Field;

public class demo {
    public void setProperty(Object obj,String propertyName,Object value) throws NoSuchFieldException, IllegalAccessException {
        Class<?> aClass = obj.getClass();
        Field field = aClass.getField(propertyName);
        if(field!=null){
            field.set(obj,value);
        }
    }
    public Object getProperty(Object obj,String propertyName) throws NoSuchFieldException, IllegalAccessException {
        Class<?> aClass = obj.getClass();
        Field field = aClass.getField(propertyName);
        return field.get(obj);
    }

}
